<?php
namespace app\services;

use Elasticsearch\ClientBuilder;
use think\facade\Log;

class EsServices{

    public function addEs($data=[]){
        //连接
        $hosts = [
            config('es.host')    // HTTP Basic Authenticationt
        ];
        $client = ClientBuilder::create()
            ->setHosts($hosts)
            ->build();

        //添加入Es库
        $params = [
            'index' => '',  //库名
            'id'    => $data['id'],    // id
            'body'  => $data  //要添加的数据
        ];

        $response = $client->index($params);

        //判断如果入库成功 存入日志
        if ($response){
            Log::info($data['id'] . '日志同步成功');
        }
    }

}